package com.sezi.vo.page;

public class Filter {
	private String filed;
	private String value;
	private CompareType compare;
	
	public Filter(){}
	
	public Filter(String filed, String value, CompareType compare){
		this.filed = filed;
		this.value = value;
		this.compare = compare;
	}
	
	public static Filter createFilter(String filed, String value, CompareType compare){
		return new Filter(filed, value, compare);
	}
	
	public String getSql(){
		StringBuilder builder = new StringBuilder(filed);
		if(compare.equals(CompareType.LIKE)){
			builder.append(" like %").append("?").append("%");
		}else{
			builder.append(compare.getValue()).append("?");
		}
		return builder.toString();
	}
	
	public String getFiled() {
		return filed;
	}

	public void setFiled(String filed) {
		this.filed = filed;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public CompareType getCompare() {
		return compare;
	}

	public void setCompare(CompareType compare) {
		this.compare = compare;
	}

	public static enum CompareType{
		GT(">"),LT("<"),EQ("="),GTEQ(">="),LTGQ("<="),LIKE("");
		private String value;
		private CompareType(String value){
			this.value = value;
		}
		public String getValue(){
			return value;
		}
	}
}
